import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ProductPageActivity extends Activity {

    private ImageView productImageView;
    private TextView productNameTextView;
    private TextView productDescriptionTextView;
    private TextView productPriceTextView;
    private TextView productStockTextView;
    private Button addToCartButton;
    private LinearLayout ratingLayout;
    private TextView averageRatingTextView;
    private Button viewReviewsButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.product_page);

        productImageView = findViewById(R.id.product_image);
        productNameTextView = findViewById(R.id.product_name);
        productDescriptionTextView = findViewById(R.id.product_description);
        productPriceTextView = findViewById(R.id.product_price);
        productStockTextView = findViewById(R.id.product_stock);
        addToCartButton = findViewById(R.id.add_to_cart_button);
        ratingLayout = findViewById(R.id.rating_layout);
        averageRatingTextView = findViewById(R.id.average_rating);
        viewReviewsButton = findViewById(R.id.view_reviews_button);

        // 模拟获取商品数据
        String productName = "特级苹果";
        String productDescription = "来自优质果园的特级苹果，色泽鲜艳，口感脆甜多汁。";
        String productPrice = "15 元/斤";
        int productStock = 50;
        double averageRating = 4.5;

        productNameTextView.setText(productName);
        productDescriptionTextView.setText(productDescription);
        productPriceTextView.setText(productPrice);
        productStockTextView.setText("库存：" + productStock + " 件");

        averageRatingTextView.setText("平均评分：" + averageRating);

        addToCartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 处理添加到购物车逻辑
                Log.d("Cart", "添加到购物车");
            }
        });

        viewReviewsButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 启动查看评价页面
                Intent reviewIntent = new Intent(ProductPageActivity.this, ReviewsActivity.class);
                startActivity(reviewIntent);
            }
        });

        // 可以根据实际需求添加更多交互和功能
    }
}